package com.sky.controller.user;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@CrossOrigin
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId") //key setmealCache::100  value 方法返回值
    public Result<List<Setmeal>> getByCategoryId( Long categoryId){
        log.info("根据分类id查询套餐：{}",categoryId);

        List<Setmeal> list = setmealService.getByCategoryIdEnabled(categoryId);

       return Result.success(list);
    }

    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishsById(@PathVariable Long id){
        log.info("根据id查询套餐内的菜品：{}",id);
        List<DishItemVO> list= setmealService.getDishsById(id);

        return Result.success(list);
    }


}
